﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace Clandestine.Battle
{
    public static class MessageWindow
    {
        private static TextSprite textSprite = Fonts.Default.DrawText(string.Empty);
        public static string Message
        {
            get { return textSprite.Text; }
            set { SetText(value); }
        }

        public static Sprite Sprite = new Sprite("battle_messages.png");

        public static Padding Padding = new Padding(2, 2, 7, 7);

        static MessageWindow()
        {
            Sprite.Layer = 1000000;
        }

        /// <summary>
        /// Gets the total height from Y = 0
        /// </summary>
        public static int Height
        {
            get { return Sprite.UnscaledHeight + Sprite.Y; }
        }


        public static void SetText(string message, params object[] formatting)
        {
            SetText(String.Format(message, formatting));
        }
        public static void SetText(string message, double duration)
        {
            SetText(message);
            Ticker.AddTimer(null, duration, false, delegate
            {
                if (Message == message)
                    ClearText();
            });
        }
        public static void SetText(string message)
        {
            textSprite.Dispose();
            textSprite = Fonts.Default2.DrawText(message);
            textSprite.Layer = Sprite.Layer + 1;
            textSprite.Y = Sprite.Y + Padding.Top;
            textSprite.X = (Graphics.ScreenWidth / 2) - (textSprite.Width / 2);
        }

        public static void ClearText()
        {
            textSprite.Visible = false;
            textSprite.Text = string.Empty;
        }

    }
}
